Skip to content

feat: add npm sync validation to NodePackageManager and theme builders#93

Merged
dermatz merged 2 commits intomainfrom
feat-npm-sync-during-build
Jan 20, 2026
Merged

feat: add npm sync validation to NodePackageManager and theme builders#93
dermatz merged 2 commits intomainfrom
feat-npm-sync-during-build

Conversation

@dermatz
Copy link
Copy Markdown
Member

@dermatz dermatz commented Jan 20, 2026

🔧 Fix: npm ci not executed when packages are out of sync

Problem

During the theme build process, npm ci was not being executed when new packages were added to package-lock.json in Hyva and TailwindCSS themes. The autoRepair() method only checked if the node_modules directory existed, not whether the installed packages matched the lock file specification.

This could lead to build failures when:

  • New dependencies were added to package.json/package-lock.json
  • Package versions were updated in the lock file
  • node_modules existed but contained outdated or missing packages

Solution

Implemented proper npm synchronization validation using npm ls to detect package state:

1. New isNodeModulesInSync() Method

File: src/Service/NodePackageManager.php

  • Added method to check if node_modules is synchronized with package-lock.json
  • Uses npm ls --depth=0 --json to validate all packages are installed with correct versions
  • Returns false when packages are missing, outdated, or have version mismatches
  • Handles edge case where package-lock.json doesn't exist (returns true)
public function isNodeModulesInSync(string $path): bool
{
    if (!$this->fileDriver->isDirectory($path . '/node_modules')) {
        return false;
    }

    if (!$this->fileDriver->isExists($path . '/package-lock.json')) {
        return true;
    }

    $result = $this->shell->execute('npm ls --depth=0 --json', $path);
    return $result->isSuccessful();
}

2. Updated Theme Builders

Files:

  • src/Service/ThemeBuilder/HyvaThemes/Builder.php
  • src/Service/ThemeBuilder/TailwindCSS/Builder.php

@dermatz dermatz requested a review from Morgy93 January 20, 2026 15:16
@dermatz dermatz enabled auto-merge (squash) January 20, 2026 15:17
@dermatz dermatz disabled auto-merge January 20, 2026 15:18
@dermatz dermatz merged commit 5fcbdaf into main Jan 20, 2026
9 checks passed
@dermatz dermatz deleted the feat-npm-sync-during-build branch January 20, 2026 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant